//
// Created by yyancy on 2019/10/29.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <fcntl.h>

void error_handling(char *string) {
    fputs(string, stderr);
    fputc('\n', stderr);
    exit(1);
}

int main() {
    int fd;
    char buf[] = "Let's go! yyancy\n";

    if ((fd = open("data.txt", O_CREAT | O_WRONLY | O_TRUNC)) == -1) {
        error_handling("open() error");
        printf("file descriptor: %d \n", fd);
    }

    if (write(fd, buf, sizeof(buf)) == -1) {
        error_handling("write() error!");
    }
    close(fd);
    return 0;

}